import unittest
# from api.userApi import UserApi
from api.apifactory import ApiFactory
import app
from analysis_data2 import AnalysisData
from parameterized import parameterized


class TestUser(unittest.TestCase):
    @parameterized.expand(AnalysisData.get_json_data("user.json", "token", ["create_code", "token_length"]))
    def test01rCeate(self, create_code, token_length):
        # create_code = 200
        # token_length = 0
        response = ApiFactory.user_api().creatApi()
        print(response.json())
        self.assertEqual(response.status_code, create_code)
        self.assertTrue(len(response.json()) > token_length)
        app.header["token"] = response.json().get("token")
        print(response.json().get("token"))

    @parameterized.expand(AnalysisData.get_json_data("user.json", "check_token", ["check_code", "check_isValid"]))
    def test02Check(self, check_code, check_isValid):
        # check_code = 200
        # check_isValid = True
        response = ApiFactory.user_api().checkApi()
        self.assertEqual(response.status_code, check_code)
        self.assertEqual(response.json().get("isValid"), check_isValid)

    @parameterized.expand(
        AnalysisData.get_json_data("user.json", "get_address", ["get_code", "get_name", "get_mobile"]))
    def test03Get(self, get_code, get_name, get_mobile):
        # get_code = 200
        # get_name = "李白"
        # get_mobile = "13012345678"
        response = ApiFactory.user_api().getApi()
        self.assertEqual(response.status_code, get_code)
        self.assertEqual(response.json().get("name"), get_name)
        self.assertEqual(response.json().get("mobile"), get_mobile)
